﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using BusinessObjects;
using DataAccess;

namespace QuanLyHopDong
{
    public partial class NamHocDetailView : Form
    {
        public event EventHandler SaveChanged;
        public event EventHandler DeleteChanged;

        private BindingList<NamHoc> bindingListNamHoc;
        private NamHoc _namHoc;

        public NamHocDetailView()
        {
            InitializeComponent();
        }
        public NamHocDetailView(NamHoc namHoc)
        {
            InitializeComponent();

            _namHoc = namHoc;
            bindingListNamHoc = new BindingList<NamHoc>();
            bindingListNamHoc.Add(_namHoc);

            bindingSourceNamHoc.DataSource = bindingListNamHoc;
            layoutControl1.Refresh();
        }

        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
        }
        private void LuuVaDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
            this.Close();
        }

        private void btnDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Xoa();
            this.Close();
        }

        void Xoa()
        {
            OnDeleteChange();
        }
        void Luu()
        {
            int reVal = 0;
            if (_namHoc.Oid ==-1)
                reVal = DataAccessObject.NamHoc.Insert(_namHoc);
            else
                reVal= DataAccessObject.NamHoc.Update(_namHoc);

            if (reVal >0)
                OnSaveChange();
        }

        private void OnSaveChange()
        {
            if (SaveChanged!=null)
                SaveChanged(this, EventArgs.Empty);
        }
        private void OnDeleteChange()
        {
            if (DeleteChanged != null)
                DeleteChanged(this, EventArgs.Empty);
        }
    }
}
